package com.naiterui.ehp.bs.recommend.util;

import com.google.common.collect.Lists;
import com.naiterui.common.redis.RedisUtil;
import com.naiterui.ehp.bp.constants.PatientIntelligentLabel;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * <pre>
 *    患者智能标签
 * </pre>
 *
 * @author 王泽浩
 * @date 2018/7/30 下午2:27
 * @since 1.0.0
 */
public class PatientIntelligentLabelUtil {

    /**
     * 设置诊断结果
     *
     * @param doctorId  医生ID
     * @param inquirerId 就诊人ID
     * @param diagnosis 诊断结果
     */
    public static void putDiagnosis(Long doctorId, Long inquirerId, List<String> diagnosis) {
        String diagnosisKey = PatientIntelligentLabel.getDiagnosisKey(doctorId);
        Assert.notNull(inquirerId, "设置复诊时间失败，患者ID不能为null");
        Assert.notNull(diagnosis, String.format("设置结果失败，复诊时间不能为null，医生id:%s 患者id:%s", doctorId, inquirerId));
        RedisUtil.hashOps().hsetObject(diagnosisKey, inquirerId + "", diagnosis);
    }

    /**
     *  获取诊断结果
     *
     * @param doctorId  医生ID
     * @param patientId 患者ID
     */
    public static List<String> getDiagnosis(Long doctorId, Long inquirerId) {
        String diagnosisKey = PatientIntelligentLabel.getDiagnosisKey(doctorId);
        Assert.notNull(inquirerId, "设置复诊时间失败，患者ID不能为null");
        List<String> list = RedisUtil.hashOps().hgetObject(diagnosisKey, inquirerId + "");
        return CollectionUtils.isEmpty(list) ? Lists.newArrayList() : list;
    }

}
